#include <utils/item.h>


namespace AccountManagerUtils {
	
//! Default constructor
Item::Item() : name_(""), value_(0.0f), category_(NULL) {}

//! Copy constructor
Item::Item(const Item& rhs) : date_(rhs.date_), name_(rhs.name_), value_(rhs.value_), category_(rhs.category_) {}

//! Constructor from a value
Item::Item(const QDate& date, ValueType value) : date_(date), name_(""), value_(value), category_(NULL) {}

//! Constructor from a value and a name
Item::Item(const QDate& date, ValueType value, const String& name) : date_(date), name_(name), value_(value), category_(NULL) {}

//! Constructor from a value, a name and a category
Item::Item(const QDate& date, ValueType value, const String& name, Category* category) : date_(date), name_(name), value_(value), category_(category) {}

//! Destructor
Item::~Item() {}

//! Assignment operator
Item& Item::operator=(const Item& rhs) {
	if ( &rhs != this ) {
		date_ = rhs.date_;
		name_ = rhs.name_;
		value_ = rhs.value_;
		category_ = rhs.category_;
	}
	return *this;
}

//! Comparison operator
bool Item::operator==(const Item& rhs) const {
	if ( date_ != rhs.date_ ) return false;
	if ( name_ != rhs.name_ ) return false;
	if ( value_ != rhs.value_ ) return false;
	return ( category_ == rhs.category_ );
}

//! Difference operator
bool Item::operator!=(const Item& rhs) const {
	if ( date_ != rhs.date_ ) return true;
	if ( name_ != rhs.name_ ) return true;
	if ( value_ != rhs.value_ ) return true;
	return ( category_ != rhs.category_ );
}

//! Accessor to the date of the item (read-write)
QDate& Item::date() {
	return date_;
}

//! Accessor to the date of the item (read only)
const QDate& Item::date() const {
	return date_;
}

//! Accessor to the name of the item (read-write)
String& Item::name() {
	return name_;
}

//! Accessor to the name of the item (read only)
const String& Item::name() const {
	return name_;
}

//! Accessor to the value of the item (read-write)
Item::ValueType& Item::value() {
	return value_;
}

//! Accessor to the value of the item (read only)
Item::ValueType Item::value() const {
	return value_;
}

//! Change the category of the item
void Item::set_category(const Category* category) {
	category_ = category;
}

//! Accessor to the category of the item (read only)
const Category* Item::category() const {
	return category_;
}

} // namespace AccountManagerUtils

